import { createApp } from 'vue'
import App from './App.vue'
import router, { setupRouter } from '@/router'
import i18n from '@/i18n/index'
import { setupStore } from '@/store'
import { setupNaive, setupDirectives, setupCustomComponents, initFunction } from '@/plugins'
import { GoAppProvider } from '@/components/GoAppProvider/index'
import { setHtmlTheme } from '@/utils'

// 引入全局样式
import '@/styles/pages/index.scss'

import '@/styles/font/iconfont.css'
// 引入动画
import 'animate.css/animate.min.css'
// 引入标尺
import 'vue3-sketch-ruler/lib/style.css'


// COMMON
import Weather from './components/Common/Weather.vue'
import DateComponent from './components/Common/Date.vue'
import TimeComponent from './components/Common/Time.vue'
import Select from './components/Common/Select.vue'
import Chart from './components/Common/Chart.vue'
import DetailModal from './packages/public/detail/index.vue'

// 递归树形结构
import VideoTree from './packages/public/tree/index.vue';
// 新闻滚动插件
// import VseamleScroll from 'vue3-seamless-scroll'
import VseamleScroll from './packages/public/scroll/index.vue'

async function appInit() {
  const goAppProvider = createApp(GoAppProvider)

  const app = createApp(App)
  app.component('c-weather', Weather)
  app.component('c-date', DateComponent)
  app.component('c-time', TimeComponent)
  app.component('c-select', Select)
  app.component('c-chart', Chart)
  app.component('c-detail', DetailModal);
  app.component('v-tree', VideoTree);
  app.component('v-scroll3', VseamleScroll)

  // 注册全局常用的 naive-ui 组件
  setupNaive(app)

  // 注册全局自定义指令
  setupDirectives(app)

  // 注册全局自定义组件
  setupCustomComponents(app)

  // 挂载状态管理
  setupStore(app)

  // 解决路由守卫，Axios中可使用，Dialog，Message 等全局组件
  goAppProvider.mount('#appProvider', true)

  // 挂载路由
  setupRouter(app)

  // 路由准备就绪后挂载APP实例
  await router.isReady()

  // Store 准备就绪后处理主题色
  setHtmlTheme()

  // 语言注册
  app.use(i18n)

  // 挂载到页面
  app.mount('#app', true)

  // 挂载到 window
  window['$vue'] = app
}

appInit().then(() => {
  initFunction()
})

